import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';
import { defHttp } from '/@/utils/http/axios';
enum Api {
  refreshCacheUrl = '/sys/spaUserRole/refreshCache',
  queryById = '/spa/spaUserRole/queryById',
  menuList = '/spa/spaMenu/menuTrue',
  PageList = '/sys/spaUserRole/listByPage',
  Add = '/sys/spaUserRole/add',
  Edit = '/sys/spaUserRole/edit',
  Delete = '/sys/spaUserRole/delete?id=',
}
const { t } = useI18n();

export const getMenuList = (params?: any) => {
  return defHttp.get<any>({ url: Api.menuList, params });
};

export const refreshCache = (params?: any) =>
  defHttp.get<any>({ url: Api.refreshCacheUrl, params });
//
export const getListByPage = (params?: any) => defHttp.get<any>({ url: Api.PageList, params });
//
export const addSpaUserRole = (params?: any) => {
  return defHttp.post<any>({ url: Api.Add, params });
};

export const editSpaUserRole = (params?: any) => {
  return defHttp.put<any>({ url: Api.Edit, params });
};

/**
 * 删除字典
 */
export const deleteSpaUserRole = (id, handleSuccess) => {
  return defHttp.delete({ url: Api.Delete + id }).then(() => {
    handleSuccess();
  });
};

export const columns: BasicColumn[] = [
  {
    title: '角色',
    dataIndex: 'roleName',
    width: 200,
  },
  {
    title: '描述',
    dataIndex: 'description',
    width: 200,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 200,
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
    width: 200,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'roleName',
    label: '角色',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '',
    required: false,
    component: 'Input',
    show: false,
  },
  {
    field: 'roleName',
    label: '角色',
    required: true,
    component: 'Input',
  },
  {
    field: 'description',
    label: '描述',
    required: false,
    component: 'Input',
  },
  {
    label: ' ',
    field: 'menus',
    slot: 'menu',
    component: 'Input',
  },
];
